#!/bin/sh

flash_indication_on() {
        echo timer > /sys/class/leds/led0:green/trigger
        echo 40 > /sys/class/leds/led0:green/delay_off
        echo 40 > /sys/class/leds/led0:green/delay_on
}

start() {
REBOOTNEEDED=0
echo "Checking for maxcpus and ad9364 mods..."
export `fw_printenv maxcpus`
export `fw_printenv attr_val`
export `fw_printenv mode`
export `fw_printenv compatible`
## Check/set dual-core mode
if [ $maxcpus == 1 ]; then
	flash_indication_on
	echo "Enabling dual-core mode..."
        fw_setenv maxcpus
        REBOOTNEEDED=1
fi

## Check/set 70-6000mhz trick (default is 325-3800Mhz)
##depends on uboot
if [ "$mode" == "" ]; then
echo "Old u-boot detected"
    if [ "$attr_val" != "ad9364" ]; then
	    flash_indication_on
	    echo "Enabling 70-6000Mhz mod..."
            fw_setenv attr_name compatible
            fw_setenv attr_val "ad9364"
            REBOOTNEEDED=1
    fi
else
    echo "New u-boot detected"
    if [ "$mode" == "1r1t" ]; then
        if [ "$compatible" != "ad9364" ]; then
	        flash_indication_on
	        echo "Enabling 70-6000Mhz mod..."
                fw_setenv compatible "ad9364"
                REBOOTNEEDED=1
        fi
    fi
fi
if [ $REBOOTNEEDED == 1 ]; then
	echo "Rebooting!"
        pluto_reboot reset
else
	echo "Mods already in place, continuing."
	
fi
}

stop() {
echo
}

# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  *)
	echo "Usage: $0 {start}"
	exit 1
esac

exit $?
